﻿using ASPNETVN.PORTAL.Components.UI;
using System;
using System.Collections;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;
using CUSTOMS.Modules.QLHS.Components.QLBB;

namespace CUSTOMS.Modules.QLHS.Controls
{
    public partial class InThongKeDanhMucHangHoaMienKiemTra : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                DateTime today = DateTime.Today;
                DateTime lastWeek = today.Subtract(new TimeSpan(7, 0, 0, 0));
                txtTuNgay.Text = lastWeek.ToShortDateString();
                txtDenNgay.Text = today.ToShortDateString();
            }
        }

        protected void btnInThongKe_Click(object sender, EventArgs e)
        {
            Hashtable settings = this.ParentControl.Settings;

            // Report.
            ReportDocument rpt = new ReportDocument();
            string path = Server.MapPath("~/Modules/CUSTOMS.Modules.QLHS/Reports/ThongKeDanhMucHangHoa.rpt");
            rpt.Load(path);

            DateTime tungay, denngay;
            tungay = Convert.ToDateTime(txtTuNgay.Text);
            denngay = Convert.ToDateTime(txtDenNgay.Text);
            DataSet ds = BienBan.InThongKeDanhMucHangHoa(tungay, denngay);

            rpt.SetDataSource(ds.Tables[0]);
            rpt.SetParameterValue("CucHaiQuan", settings["CucHaiQuan"].ToString());
            rpt.SetParameterValue("HaiQuanCaiDat", settings["TenHaiQuan"].ToString());
            rpt.SetParameterValue("SoBienBan", txtSoBienBan.Text);

            Session["CUSTOMS.Modules.QLHS.Report"] = rpt;
            Response.Redirect(string.Format("~/Modules/CUSTOMS.Modules.QLHS/ViewReport.aspx?tabid={0}&mid={1}", this.TabID, this.ModuleID));
        }
    }
}